import os,sys
import pprint

import yaml
from common.readconfig import Environ

# def get_yaml_filepath(Environ="",filepath=""):
#     Environ1 = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) + Environ + "/data.yaml"     #拼接定位到文件夹
#     filepath1 = os.path.abspath(os.path.dirname(os.path.dirname(__file__)) + r"/data") +"/" + filepath      #定位到data文件夹
#     if Environ:
#         with open(Environ1,"r",encoding="utf-8")as f:
#             return Environ1
#     if filepath:
#         with open(filepath1,"r",encoding="utf-8")as f:
#             return yaml.load(f,Loader=yaml.FullLoader)
#
# if __name__ == '__main__':
#
#     print('ggg',get_yaml_filepath(filepath="login.yaml"))
#     print('aaa',os.path.dirname(os.path.abspath(os.path.dirname(__file__))) + Environ)
#     print('ddd', get_yaml_filepath(Environ=Environ))

class ReadYamlConfigs():
    def __init__(self,filename):
        self.filepath = (os.path.dirname(os.path.abspath(os.path.dirname(__file__))) + Environ) + "/" + filename

    def get_yaml_data(self):
        with open(self.filepath, "r", encoding="utf-8")as f:
            return yaml.load(f, Loader=yaml.FullLoader)

class ReadYamlData():
    def __init__(self,filename):
        self.filepath = (os.path.dirname(os.path.abspath(os.path.dirname(__file__))) + r"/data") + "/" + filename   #拼接定位到data文件夹
    def get_yaml_data(self):
        with open(self.filepath,"r",encoding="utf-8")as f:
            return yaml.load(f,Loader=yaml.FullLoader)

# if __name__ == '__main__':
    # data = ReadYamlData('login.yaml').get_yaml_data()['data']
    # print(data['mobile'])
    # pprint.pprint(ReadYamlData('login.yaml').get_yaml_data())
